﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Markup;

namespace WPFTrees
{
    /// <summary>
    /// Interaction logic for SettingsDlg.xaml
    /// </summary>
    public partial class SettingsDlg : Window
    {
        Shape _nodeShape;
        Shape innerShape, leafShape;

        /// <summary>
        /// Initializes new instance of dialog.
        /// </summary>
        /// <param name="nodeShape">Shape of node.</param>
        public SettingsDlg(Shape nodeShape)
        {            
            InitializeComponent();

            _nodeShape = nodeShape;

            string s = XamlWriter.Save(_nodeShape);
            innerShape = (Shape)XamlReader.Parse(s);
            leafShape = (Shape)XamlReader.Parse(s);
            gridSizes.Children.Add(innerShape);
            gridSizes.Children.Add(leafShape);
            Grid.SetColumn(innerShape, 1);
            Grid.SetColumn(leafShape, 1);
            Grid.SetRow(innerShape, 1);
            Grid.SetRow(leafShape, 0);

            slider1.Value = leafShape.Height;
            slider2.Value = innerShape.Height;
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            
        }

        private void slider1_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            if(leafShape!=null)
                leafShape.Height = leafShape.Width = slider1.Value;
        }

        private void slider2_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            if (innerShape != null)
                innerShape.Height = innerShape.Width = slider2.Value;
        }

        /// <summary>
        /// Gets/sets size of inner node.
        /// </summary>
        public double InnerNodeSize {
            get { return innerShape.Height; }
            set { slider2.Value = value; }
        }

        /// <summary>
        /// Gets/sets size of leaf node.
        /// </summary>
        public double LeafNodeSize
        {
            get { return leafShape.Height; }
            set { slider1.Value = value; }
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = true;
        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
        }
    }
}
